package dao

import (
	"user/inits"
	"user/model"
)

func GetUser(name string) (result *model.User, err error) {
	err = inits.DB.Where("name=?", name).Where("deleted=?", 0).First(&result).Error
	if err != nil {
		return nil, err
	}
	return result, nil
}

func Register(name string, password string) (result *model.User) {
	result = &model.User{
		Name:     name,
		Password: password,
	}
	err := inits.DB.Create(&result).Error
	if err != nil {
		return nil
	}
	return result
}

func Login(name string, password string) (result *model.User) {
	err := inits.DB.Where("name=?", name).Where("password=?", password).Find(&result).Error
	if err != nil {
		return nil
	}
	return result
}
